package com.zang.hash;

import java.util.HashMap;

/**
 * @author ZVerify
 * @since 2022/10/13 10:04
 **/
public class 两数之和 {

    public int[] twoSum(int[] nums, int target) {

        HashMap<Integer, Integer> map = new HashMap<>();

        int[] ints = new int[2];
        int i = 0;

        for (int num : nums) {

            if (map.containsKey(target-num)){
                ints[0] = map.get(target-num);
                ints[1] = i;
            }else {
                map.put(num,i);
            }
            i++;
        }
        return ints;
    }
}
